<template>
  <div>
    <el-table v-loading="loading" :data="orderList" stripe>
      <el-table-column type="index" width="40" />
      <el-table-column prop="username" label="申请人" />
      <el-table-column label="图片">
        <template slot-scope="scope">
          <img :src="scope.row.download_url" alt height="50" />
        </template>
      </el-table-column>
      <el-table-column prop="giftname" label="礼物名字" />
      <el-table-column prop="createTime" label="兑换时间" />
      <el-table-column prop="code" label="邮编" />
      <el-table-column prop="region" label="地区" />
      <el-table-column prop="info" label="收货地址" />
      <el-table-column prop="ph" label="手机号码" />
      <el-table-column prop="name" label="收货人" />
      <el-table-column prop="state" label="状态" />

      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="onEdit(scope.row)">修改</el-button>
          <!-- <el-button size="mini" type="danger" @click="onDel(scope.row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 确认删除的对话框 -->
    <!-- <el-dialog title="提示" :visible.sync="delDialogVisible" width="30%">
      <span>确定删除该博客吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="delDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="doDel">确 定</el-button>
      </span>
    </el-dialog>-->
  </div>
</template>

<script>
import { fetchList, del } from "@/api/order";
import scroll from "@/utils/scroll";
export default {
  data() {
    return {
      orderList: [],
      count: 50,
      loading: false, // 加载动画
      delDialogVisible: false, // 删除的对话框是否显示
      order: {},
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    scroll.start(this.getList);
  },
  methods: {
    unixTimeToDateTime(unixtime) {
      var now = new Date(unixtime), // 依情况进行更改 * 1
        y = now.getFullYear(),
        m = now.getMonth() + 1,
        d = now.getDate();
      return (
        y +
        "-" +
        (m < 10 ? "0" + m : m) +
        "-" +
        (d < 10 ? "0" + d : d) +
        " " +
        now.toTimeString().substr(0, 8)
      );
    },
    getList() {
      this.loading = true;
      fetchList({
        start: this.orderList.length,
        count: this.count,
      }).then((res) => {
        console.log(res);
        console.log(this.unixTimeToDateTime(res.data[0].createTime.$date));
        this.orderList = this.orderList.concat(res.data);
        for (var i = 0; i < this.orderList.length; i++) {
          this.orderList[i].createTime = this.unixTimeToDateTime(
            res.data[i].createTime.$date
          );
        }
        if (res.data.length < this.count) {
          scroll.end();
        }
        this.loading = false;
      });
    },
    onEdit(row) {
      this.$router.push(`/order/edit/${row._id}`);
    },
    // onDel(row) {
    //   this.delDialogVisible = true;
    //   this.order = row;
    // },
    // doDel() {
    //   this.loading = true;
    //   this.delDialogVisible = false;
    //   del(this.order).then((res) => {
    //     this.loading = false;
    //     // console.log(res)
    //     if (res.data.delBlogRes.deleted > 0) {
    //       this.orderList = [];
    //       this.getList();
    //       this.$message({
    //         message: "删除成功",
    //         type: "success",
    //       });
    //     } else {
    //       this.$message.error("删除失败");
    //     }
    //   });
    // },
  },
};
</script>

<style>
</style>
